package logic

import (
	"context"
	"errors"
	"shop/model/mysql"
	"shop/shopclient"

	"shop/internal/svc"
	"shop/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseShowLogic {
	return &HouseShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseShowLogic) HouseShow(in *shop.HouseShowRequest) (*shop.HouseShowResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var h mysql.House
	if err = h.GetByUserId(); err != nil {
		logx.Error("用户未发布房源")
		return nil, errors.New("用户未发布房源")
	}
	var as []mysql.Auther
	var hs []mysql.House
	mysql.DB.Find(&as)
	mysql.DB.Find(&hs)
	var houseShow []*shopclient.HouseShow
	for _, k := range hs {
		houseShow = append(houseShow, &shopclient.HouseShow{
			Title: k.Title,
			Price: float32(k.Price),
			Num:   int64(k.Num),
			Info:  k.Info,
			Image: k.Image,
		})
	}
	for _, a := range as {
		houseShow = append(houseShow, &shopclient.HouseShow{
			IdCard:   a.IdCard,
			RealName: a.RealName,
		})
	}
	return &shop.HouseShowResponse{
		List: houseShow,
	}, nil
}
